package com.woniu.controller;

import com.woniu.entity.Product;
import com.woniu.service.ProductService;
import com.woniu.service.impl.ProductServiceImpl;

import java.util.List;

public class ProductController {
    public static List<Product> getProductList(){
        ProductServiceImpl productService = new ProductServiceImpl();
        List<Product> products = productService.selectAllProduct();
        return products;
    }
    public static Product getProductById(int pid){
        ProductServiceImpl productService = new ProductServiceImpl();
        Product product = productService.selectProductById(pid);
        return product;
    }

    public static void updateProductStock(Integer pid, int stock){
        ProductServiceImpl productService = new ProductServiceImpl();
        productService.UpdateProductStock(pid, stock);
    }

    public static List<Product> getProductByUid(int merchant_id){
        ProductServiceImpl productService = new ProductServiceImpl();
        List<Product> products = productService.selectProductByUid(merchant_id);
        return products;
    }
    public static void insertProduct(Product product){
        ProductServiceImpl productService = new ProductServiceImpl();
        productService.insertProduct(product);
    }

    public static void updateProductPrice(Integer pid, double price){
        ProductServiceImpl productService = new ProductServiceImpl();
        productService.updateProductPrice(pid, price);
    }

    public static void deleteProduct(int pid){
        ProductServiceImpl productService = new ProductServiceImpl();
        productService.deleteProductById(pid);
    }
    public static void deleteProductByMerchantId(int merchant_id){
        ProductServiceImpl productService = new ProductServiceImpl();
        productService.deleteProductByMerchantId(merchant_id);
    };
    public static List<Product> selectProductByName(String pname){
        ProductServiceImpl productService = new ProductServiceImpl();
        List<Product> products = productService.selectProductByName(pname);
        return products;
    }
    public static Product selectProductMidName(Integer merchant_id, String pname) {
        ProductServiceImpl productService = new ProductServiceImpl();
        Product product = productService.selectProductMidName(merchant_id, pname);
        return product;
    }
    }
